<?php
/**
 * Created by PhpStorm.
 * User: 胡毅       服饰
 * Date: 2016/1/24
 * Time: 17:24
 */
class FsAction extends Action{
  public function fs(){
    $this->display('fs');
  }
    public function fs1(){
      $this->display('fs1');
    }
    public function fs2(){
     $this->display('fs2');
    }
    public function fs3(){
        $this->display('fs3');
    }
    public function fs4(){
        $this->display('fs4');
    }
    public function fs5(){
        $this->display('fs5');
    }
    /*
     * fs6  有优惠券验证
     */
    public function fs6(){
        $model=M("user");
        if(isset($_SESSION['phone'])) {
            $phone = $_SESSION['phone'];         //$fs_6 = 'zlf-06.png,zlf-08.png,zlf-10.png';
            $info = $model->where("phone=" . $phone)->find();
            $_SESSION['pId'] = $info['pId'];  //把查询到的手机号码用户id存入session
            $pidList = $info['pId'];

            $sql1 = "select id,yhpic from pics where id not in($pidList) and yhpic like 'zlf-%'";  //查询用户没使用图片的id    uId in($uid) or
            $sql2="select id,yhpic from pics where id in($pidList) and yhpic like 'zlf-%'";//查询用户使用图片的id
            $images2=M('pics')->query($sql2);
            $images = M("pics")->query($sql1);

            $this->assign("info", $info);
            $this->assign("images2", $images2);
            $this->assign("images", $images);//查询用户没使用图片
        }
        $this->display('fs6');
    }
    //检测手机号码   用户没有登陆的状态下
    public function check_fs6(){
       if(isset($_POST['button'])){
            $model=M("user");
            $phone=$_POST['phone'];
            $_SESSION['phone']=$_POST['phone'];
            $info=$model->where("phone=".$phone)->find();
            if($info){
                $_SESSION['pId']=$info['pId'];  //把查询到的手机号码用户id存入session
                $pidList=$info['pId'];

                $sql1 = "select id,yhpic from pics where id not in($pidList) and yhpic like 'zlf-%'";  //查询用户没使用图片的id    uId in($uid) or
                $sql2="select id,yhpic from pics where id in($pidList) and yhpic like 'zlf-%'";//查询用户使用图片的id
                $images2=M('pics')->query($sql2);
                $images = M("pics")->query($sql1);

                $this->assign("info",$info);
                $this->assign("images2",$images2);
                $this->assign("images",$images);//查询用户没使用图片
                $this->display("fs6");
            }else{
                $this->redirect("Fs/fs6");exit;
            }
       }else{
           $this->redirect("Fs/fs6");
        }
    }
    //确定使用优惠券后改变状态入库----------------------共享开始--------------------------------------------------
    public function hit(){
        $model=M('user');
        $pid=$_GET['pid'];
        $uid=$_GET['uid'];  //将图片id放入用户id
        $pids=$model->where("id=".$uid)->field('pId')->find();
        $pidList=$pids['pId'].','.$pid;
        $data=array(
            'id'=>$uid,
            'pId'=>trim($pidList,','),
        );
        if($model->save($data)) {
            $this->ajaxReturn("使用成功");
        }else{
            $this->ajaxReturn("使用失败");
        }
    }

}